package com.pattern.demo.javaapi;

import com.pattern.demo.protogenesis.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * @ClassName: CurrentConditionsDisplay   当前时间温度、湿度看板
 * @Description:
 * @Date: 2020/8/27 15:15
 * @Author: Song JinGen
 */
public class CurrentConditionsDisplayByJdk implements Observer, DisplayElement {
    private Observable observable;
    /**
     *  温度
     */
    private float temperature;

    /**
     * 湿度
     */
    private float humidity;

    private String msg;

    public CurrentConditionsDisplayByJdk(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }

    /**
     * 天气展示看板
     */
    public void display() {
        System.out.println("基于JAVA API 当前时间温度情况：【 温度 ："+temperature+"F ；湿度："+humidity+"% ; 详细信息："+msg+"】");
    }

    /**
     * 更新天气情况
     *
     * @param o
     * @param arg
     */
    public void update(Observable o, Object arg) {
        if ( o instanceof WeatherDataByJdk){
            WeatherDataByJdk observable =(WeatherDataByJdk)o;
            this.temperature = observable.getTemperature();
            this.humidity = observable.getHumidity();
            this.msg = observable.getMsg();
            display();
        }
    }
}
